package com.manli.api.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.manli.api.pojo.QueryParamsGoodsModel;
import com.manli.api.pojo.QueryParamsGoodsModelDel;
import com.manli.api.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.manli.api.base.annotation.Permissions;
import com.manli.api.pojo.QueryParams;
import com.manli.api.dto.GoodsModel;
import com.manli.api.service.GoodsModelService;



/**
 * 
 *
 * @author manli
 * @email 
 * @date 2020-05-12 09:11:18
 */
@Api(value="/goodsmodel", tags="商品规格")
@RestController
@RequestMapping("api/goodsmodel")
public class GoodsModelController {
    @Autowired
    private GoodsModelService goodsModelService;

    /**
     * 列表
     */
    @ApiOperation(value = "列表",notes = "")
    @PostMapping("/list")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    public Result list(@RequestBody QueryParamsGoodsModel params){
        return goodsModelService.queryPage1(params);
    }

    /**
     * 全部数据信息
     */
    @ApiOperation(value = "全部数据信息",notes = "")
    @PostMapping("/all")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    public Result all(@RequestBody QueryParamsGoodsModel params){
        return goodsModelService.queryAll(params);
    }

    /**
     * 单条信息
     */
    @ApiOperation(value = "单条信息",notes = "单条信息")
    @GetMapping("/info/{goodsModelId}")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    public Result info(@PathVariable("goodsModelId") Integer goodsModelId){
        return goodsModelService.getById(goodsModelId);
    }

    /**
     * 保存
     */
    @ApiOperation(value = "保存",notes = "保存")
    @PostMapping("/save")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    public Result save(@RequestBody GoodsModel goodsModel){
        return goodsModelService.save(goodsModel);
    }

    /**
     * 批量保存
     */
    @ApiOperation(value = "批量保存",notes = "批量保存")
    @PostMapping("/listSave")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    public Result listSave(@RequestBody List<GoodsModel> goodsModels){
        return goodsModelService.listSave(goodsModels);
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改",notes = "修改")
    @PostMapping("/update")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    public Result update(@RequestBody GoodsModel goodsModel){
        return goodsModelService.updateById(goodsModel);
    }

    /**
     * 删除单条数据
     */
    @ApiOperation(value = "删除",notes = "删除")
    @ApiImplicitParam(name = "goodsModelIds", value = "id",dataType = "int", required = true)
    @PostMapping("/delete")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    public Result delete(@RequestBody QueryParamsGoodsModelDel goodsModelId){
        return goodsModelService.removeById(goodsModelId);
    }

    /**
     * 删除多条数据
     */
    @ApiOperation(value = "删除",notes = "删除")
    @ApiImplicitParam(name = "goodsModelIds", value = "id数组,json字符串",dataType = "id数组,json字符串", required = true)
    @PostMapping("/deleteIds")
    @Permissions(module = "", privilege = "", typeOfAccess = Permissions.METHOD_LOGIN)
    public Result deleteIds(@RequestBody Integer[] goodsModelIds){
        return goodsModelService.removeByIds(Arrays.asList(goodsModelIds));
    }

}
